package com.bjdd.jdy.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.bjdd.jdy.Constant;
import com.bjdd.jdy.R;
import com.bjdd.jdy.util.ImageUtil;
import com.bjdd.jdy.util.L;
import com.bjdd.jdy.util.T;

import java.util.List;

/**
 * Created by Administrator on 2017/5/2.
 */

public class ImageAdapter extends BaseAdapter {
    private List<String> paths;
    private Context context;
    private ImageUtil imageUtil;
    private int MAX;
    public ImageAdapter(Context context,List<String> list,int max){
        this.context = context;
        this.paths = list;
        imageUtil = new ImageUtil(context);
        this.MAX = max;
    }
    @Override
    public int getCount() {
        return paths.size();
    }

    @Override
    public Object getItem(int position) {
        return paths.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null){
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_img,null);
            viewHolder.img = (ImageView)convertView.findViewById(R.id.img_photo);
            convertView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        if (paths.get(position).equals(Constant.DEFAULT_PHOTO)){
            imageUtil.loadResImage(R.mipmap.img_photo,viewHolder.img);
        }else {
            imageUtil.loadLocalImage(paths.get(position),viewHolder.img);
        }

        return convertView;
    }
    class ViewHolder{
        ImageView img;

        public ImageView getImg() {
            return img;
        }

        public void setImg(ImageView img) {
            this.img = img;
        }
    }
}
